package IntelSpam::Filters::GTubeFilter;

use 1.0;

use warnings;
use IntelSpam::Config;
use Data::Dumper;
use Sys::Syslog;

our $VERSION = '1.0';
our $DEBUG = 1;

our $REGISTER = ['body'];
our $META = {
	'id' => 'gtube_filter',
	'name' => 'GTUBE Filter',
	'description' => 'Spam GTUBE Test http://spamassassin.apache.org/gtube/',
	'version' => '1.0',
	'weight' => 50
	
};


sub new($){
	bless {}, shift;
}

sub filter_body($$$)
{
	my ($this, $ctx, $entity) = @_;
	
	#print Dumper ($entity->body_as_string());
	find_gtube($ctx, $entity);
	0;
}


sub find_gtube
{	
	my ($ctx, $entity, $name) = @_;
    defined($name) or $name = "'anonymous'";
    my $IO;


    # Output the body:
    my @parts = $entity->parts;
    if (@parts) {                     # multipart...
	my $i;
	foreach $i (0 .. $#parts) {       # dump each part...
	    find_gtube($ctx, $parts[$i], ("$name, part ".(1+$i)));
	}
    }
    else {    
		my ($type, $subtype) = split('/', $entity->head->mime_type);
		if($type =~ /^text$/){
			my $contents = $entity->body_as_string();
			print $contents;
			
			if($contents =~ /XJS\*C4JDBQADN1.NSBN3\*2IDNEN\*GTUBE\-STANDARD\-ANTI\-UBE\-TEST\-EMAIL\*C\.34X/i){
				
				$ctx->getpriv()->{'score'}->insert($META->{'id'}, $META->{'weight'}, 445048239348);
			}
		}
	}
}

sub get_registers($){
	$REGISTER;
}

sub get_meta($){
	$META;
}

sub set_cfg($$){

	
}

1;

